package org.example.service.delay;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author Tang
 * @classname DelaySender
 * @description [  ]
 * @date 2023/4/10 22:06
 */
@Slf4j
//@Component
public class DelaySender implements CommandLineRunner {

    @Resource
    RabbitTemplate rabbitTemplate;

    @Override
    public void run(String... args) throws Exception {
        log.info("DelaySender... start ...");
        rabbitTemplate.convertAndSend("email.change", "1.email.key", "email info msg!", message -> {
            message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
            message.getMessageProperties().setExpiration("5000");
            return message;
        });
        rabbitTemplate.convertAndSend("email.change","2.email.key", "email error msg!", message -> {
            message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
            message.getMessageProperties().setExpiration("10000");
            return message;
        });
    }

}
